<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> Crosstable test </TITLE>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  <link type="text/css" rel="stylesheet" href="http://jqueryui.com/themes/base/ui.all.css" />
  <link rel="stylesheet" type="text/css" media="screen" href="css/style.css">
		<script type="text/javascript" src="js/json2.js"></script>
		<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
		<script type="text/javascript" src="js/dsjqcrosstable.js"></script>
		<script type="text/javascript" src="data.js"></script>
		<script type="text/javascript" src="http://jqueryui.com/themeroller/themeswitchertool/"></script>
		<script type="text/javascript">
			//SortObjArray(olapdata,[{colname:'Race',direction:'asc'},{colname:'Attack',direction:'desc'},{colname:'VulName',direction:'asc'}]);
			//SortObjArray(redata,[{colname:'type',direction:'asc'},{colname:'datetime',direction:'asc'}]);
			$(document).ready(function(){
				$('#switcher').themeswitcher();
				//$("#cross1").jqCrossTable({
					//rows:[
						//{name:'Race', caption:'Юнит', displayvalue:function(cur){return cur['Race']}},
						//{name:'Attack', caption:'Атака'},
						//{name:'Name', caption:'Раса'}
					//],
					//cols:[
						//{name:'VulName', caption:'Юнит'}
					//],
					//detail:[
						//{caption:'Урон', width:100, value:function(cur,dimvalues){
							//return cur['VulDamage'] || 0;
						//}}
					//],
					//jsonReader: {root:'data'},
					//datastr:'{data:olapdata}',
					//showDetailCaption: false
				//});
				//$("#cross2").jqCrossTable({
					//rows:[
						//{name:'type', caption:'тип', displayvalue:function(cur){return cur['type'];}
						//},
						//{name:'datetime', caption:'время', displayvalue:function(cur){return new Date(cur['datetime']).toLocaleTimeString();},
							//rowdetail:[
								//{name:'player'},
								//{name:'sote'},
								//{name:'army'}
							//]
						//}
					//],
					//cols:[
						////{name:'VulName', caption:'Юнит', width: 30, dimvalue:function(cur){return cur['VulName'];}}
					//],
					//detail:[
						//{caption:'ПЭ', width:40, value:function(cur,dimvalues){
							//return cur['prodeq'] || 0;
						//}},
						//{caption:'К', width:50, value:function(cur,dimvalues){
							//return cur['kaderium'] || 0;
						//}},
						//{caption:'НК', width:60, value:function(cur,dimvalues){
							//return cur['nanocrystals'] || 0;
						//}},
						//{caption:'Е', width:70, value:function(cur,dimvalues){
							//return cur['food'] || 0;
						//}},
						//{caption:'СЭ', width:80, value:function(cur,dimvalues){
							//return cur['energy'] || 0;
						//}},
						//{caption:'П', width:90, value:function(cur,dimvalues){
							//return cur['prodium'] || 0;
						//}}
					//],
					//jsonReader: {root:'data'},
					//datastr:'{data:redata}',
					//showDetailCaption: true
				//});
				
				$("#cross3").jqCrossTable({
					rows:[
						{name:'defence_Юнит', caption:'тип', 
							rowdetail:[
								{name:'defence_Количество', cellclass: 'tdright', width:50},
								{name:'defence_Dam', width:60, cellclass: 'tdright', calculated:function(cur){
										var unit = getUnitByName(cur['defence_Юнит']);
										if (unit)
										{
											return (unit['ЭффективныйУрон']*cur['defence_Количество']).toFixed(0);
										}
										else
											return 0;
									}
								},
								{name:'defence_Hits', width:50, cellclass: 'tdright', calculated:function(cur){
										var unit = getUnitByName(cur['defence_Юнит']);
										if (unit)
										{
											return (unit['ЭффективнаяБроня']*cur['defence_Количество']).toFixed(0);
										}
										else
											return 0;
									}
								}
							]
						}
					],
					cols:[
						{name:'attack_Юнит', caption:'тип', width: 30,
							coldetail:[
								{name:'attack_Количество', cellclass: 'tdright'},
								{name:'attack_Dam', cellclass: 'tdright', calculated:function(cur){
										var unit = getUnitByName(cur['attack_Юнит']);
										if (unit)
										{
											return (unit['ЭффективныйУрон']*cur['attack_Количество']).toFixed(0);
										}
										else
											return 0;
									}
								},
								{name:'attack_Hits', cellclass: 'tdright', calculated:function(cur){
										var unit = getUnitByName(cur['attack_Юнит']);
										if (unit)
										{
											return (unit['ЭффективнаяБроня']*cur['attack_Количество']).toFixed(0);
										}
										else
											return 0;
									}
								}
							]
						}
					],
					detail:[
						{caption:'Урон атаки', width:70, footer:'sum', cellclass:'tdright', value:function(cur,dimvalues){
							var unit = getUnitByName(cur['attack_Юнит']);
							if (unit)
							{
								if (unit['Vulnerabilities'])
								{
									var unitunit = getUnitFromUnitByName(unit['Vulnerabilities'],cur['defence_Юнит']);
									if (unitunit)
									{
										return (unit['ЭффективныйУрон']*(cur['attack_Количество'] || 0)/b2.length*unitunit['Урон']).toFixed(0);
									}
									else
									{
										var otherunit = getUnitByName(cur['defence_Юнит']);
										if (otherunit)
										{
											if (otherunit['Vulnerabilities'])
											{
												otherunitunit = getUnitFromUnitByName(otherunit['Vulnerabilities'],cur['attack_Юнит']);
												if (otherunitunit)
												{
													return (unit['ЭффективныйУрон']*(cur['attack_Количество'] || 0)/b2.length*otherunitunit['УронПротивника']).toFixed(0);
												}
												else
													return 0;
											}
											else
												return 0;
										}
										else
											return 0;
									}
								}
								else
									return 0;
							}
							else
								return 0;
						}},
						{caption:'Урон защиты', width:80, footer:'sum', cellclass:'tdright', value:function(cur,dimvalues){
							var unit = getUnitByName(cur['defence_Юнит']);
							if (unit)
							{
								if (unit['Vulnerabilities'])
								{
									var unitunit = getUnitFromUnitByName(unit['Vulnerabilities'],cur['attack_Юнит']);
									if (unitunit)
									{
										return (unit['ЭффективныйУрон']*(cur['defence_Количество'] || 0)/b1.length*unitunit['Урон']).toFixed(0);
									}
									else
									{
										var otherunit = getUnitByName(cur['attack_Юнит']);
										if (otherunit)
										{
											if (otherunit['Vulnerabilities'])
											{
												otherunitunit = getUnitFromUnitByName(otherunit['Vulnerabilities'],cur['defence_Юнит']);
												if (otherunitunit)
												{
													return (unit['ЭффективныйУрон']*(cur['defence_Количество'] || 0)/b1.length*otherunitunit['УронПротивника']).toFixed(0);
												}
												else
													return 0;
											}
											else
												return 0;
										}
										else
											return 0;
									}
								}
								else
									return 0;
							}
							else
								return 0;
						}}
					],
					jsonReader: {root:'data'},
					datastr:'{data:battle}',
					showDetailCaption: true,
					contenttdclass:'tdright'
				});
				//$("#cross4").jqCrossTable({
					//cols:[
						//{name:'defence_Юнит', caption:'тип', 
							//coldetail:[
								//{name:'defence_Количество'}
							//]
						//}
					//],
					//rows:[
						//{name:'attack_Юнит', caption:'тип', 
							//rowdetail:[
								//{name:'attack_Количество', width:60}
							//]
						//}
					//],
					//detail:[
						//{caption:'АК', width:70, value:function(cur,dimvalues){
							//return cur['attack_Количество'] || 0;
						//}},
						//{caption:'ЗК', width:80, value:function(cur,dimvalues){
							//return cur['defence_Количество'] || 0;
						//}}
					//],
					//jsonReader: {root:'data'},
					//datastr:'{data:battle}',
					//showDetailCaption: true
				//});
			});

		</script>
 </HEAD>

 <BODY>
<!-- <div id="cross1">
 </div>
 <div id="cross2">
 </div>-->
 <div id="cross3">
 </div>
<!-- <div id="cross4">
 </div>-->
 <div id="switcher"></div>
 </BODY>
</HTML>
